#include <stdio.h>
#include <stdlib.h>

/**
 * 链表实现栈
 */
typedef struct StackNode{
    int data;
    struct StackNode * next;
} * StackLinkList;

/**
 * 初始化栈
 * @param stack
 */
void initStackLinkList(StackLinkList stackHead){
    stackHead->next = NULL;
}

/**
 * 入栈（头插法）
 */
_Bool push(StackLinkList stackHead, int data) {
    struct StackNode * newNode = malloc(sizeof (StackLinkList));
    newNode->data = data;
    newNode->next = stackHead->next;
    stackHead->next = newNode;
    return 1;
}

/**
 * 出栈
 */
int pop(StackLinkList stackHead) {
    struct StackNode * temp = stackHead->next;
    stackHead->next = temp->next;
    int data = temp->data;
    free(temp);
    return data;
}

void printStack(StackLinkList stackHead) {
    while(stackHead->next) {
        stackHead = stackHead->next;
        printf("%d\t", stackHead->data);
    }
}


int main() {
    struct StackNode stack;
    initStackLinkList(&stack);
    push(&stack, 10);
    push(&stack, 20);
    push(&stack, 30);
    pop(&stack);
    printStack(&stack);
}